package leetcode.weekly.week329;

//Solution3Test
public class Solution3 {

	public boolean makeStringsEqual(String s, String target) {
		int zero = 0, one = 0;
		int n = s.length();
		int cntZero = 0, cntOne = 0;
		// 00,11,01,10
		boolean b00 = false, b11 = false, b01 = false, b10 = false;
		for (int i = 0; i < n; i++) {
			char cs = s.charAt(i);
			char ct = target.charAt(i);
			if (cs == '0') {
				cntZero++;
			} else {
				cntOne++;
			}
			if (cs == ct) {
				if (cs == '0') {
					b00 = true;
				} else {
					b11 = true;
				}
			} else if (cs == '0') {
				b01 = true;
				zero++;
			} else {
				b10 = true;
				one++;
			}
		}
		if (zero == one) {
			return true;
		} else if (one > zero) {
			return (cntZero > 0 && b01) || (cntOne > 1 && b11);
		} else if (zero > one) {
			return (cntOne > 0 && b10) || (cntOne > 0 && b11);
		}
		return false;
	}

}
